package Windows.Tree;

import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreePath;

public class ResTree extends JScrollPane {
	public final JTree jTree;
	public final TreeNodePic rootNode;
	public final ResTreeModel TreeModel;

	public ResTree(TreeNodePic tnp) {
		rootNode = tnp;
		jTree = new JTree();
		TreeModel = new ResTreeModel(jTree, rootNode);// 树模型
		jTree.setCellRenderer(new PicTreeCellRenderer());
		this.setViewportView(jTree);
		jTree.expandRow(0);// 展开一个结点

//	    new Thread(new Runnable(){
//
//			public void run() {
//				while(true){
//				if(jTree!=null){
//					jTree.updateUI();
//				}
//				try {
//					Thread.sleep(3000);
//				} catch (InterruptedException e) {}
//				}
//			}}).start();
	}

	public void addNode(MutableTreeNode tn) {
		rootNode.add(tn);
//	    node3.setAllowsChildren(true);//允许有子节点   
//	    jTree.expandRow(3);//展开一个结点
//	    jTree.expandRow(jTree.getRowCount()-3);//展开一个结点
//		jTree.addSelectionRow(1);
		jTree.updateUI();

	}

	public JTree getJTree() {
		return jTree;
	}

	/**
	 * 取当前选中路径
	 * 
	 * @return
	 */
	public TreePath getPath() {
		return jTree.getSelectionPath();
	}
}
